home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_q_t / trem.zip / DIALOG.C < prev    next >
Text File  |  1991-05-11  |  9KB  |  288 lines

  1. /************************************************************************
  2.  *
  3.  *    Copyright (c) 1991 Microsoft Corporation.  All Rights Reserved.
  4.  *
  5.  *-----------------------------------------------------------------------
  6.  *
  7.  *     Project:  Windows Terminal Example
  8.  *
  9.  *      Module:  dialog.c
  10.  *
  11.  *      Author:  Bryan A. Woodruff (baw)
  12.  *
  13.  *
  14.  *     Remarks:  Dialog boxes are controlled with these procs.
  15.  *
  16.  *   Revisions:  
  17.  *     01.00.000  5/10/91 baw   Wrote it.
  18.  *
  19.  ************************************************************************/
  20.  
  21. #include "terminal.h"
  22.  
  23. /************************************************************************
  24.  *  VOID GoModalDialogBoxParam ( HANDLE hInstance, LPSTR lpszTemplate,
  25.  *                               HWND hWnd, FARPROC lpDlgProc,
  26.  *                               DWORD dwParam )
  27.  *
  28.  *  Description: 
  29.  *     Invokes a modal dialog box with DWORD parameter.
  30.  *
  31.  *  Comments:
  32.  *      5/10/91  baw  Wrote it.
  33.  *
  34.  ************************************************************************/
  35.  
  36. VOID GoModalDialogBoxParam( HANDLE hInstance, LPSTR lpszTemplate,
  37.                             HWND hWnd, FARPROC lpDlgProc, DWORD dwParam )
  38. {
  39.    FARPROC  lpProcInstance ;
  40.  
  41.    lpProcInstance = MakeProcInstance( lpDlgProc, hInstance ) ;
  42.    DialogBoxParam( hInstance, lpszTemplate, hWnd, lpProcInstance, dwParam ) ;
  43.    FreeProcInstance( lpProcInstance ) ;
  44.  
  45. } /* end of GoModalDialogBox() */
  46.  
  47. /************************************************************************
  48.  *  int GetRadioButton( HWND hDlg, int nIDFirst, int nIDLast )
  49.  *
  50.  *  Description: 
  51.  *     Returns the ID value of the selected radio button.
  52.  *
  53.  *  Comments:
  54.  *      5/11/91  baw  Wrote it.
  55.  *
  56.  ************************************************************************/
  57.  
  58. int GetRadioButton( HWND hDlg, int nIDFirst, int nIDLast )
  59. {
  60.    int i ;
  61.  
  62.    for (i = nIDFirst; i <= nIDLast; i++)
  63.       if (IsDlgButtonChecked( hDlg, i ))
  64.          return ( i ) ;
  65.  
  66.    return ( nIDFirst ) ;
  67.  
  68. } /* end of GetRadioButton() */
  69.  
  70. /************************************************************************
  71.  *  BOOL FAR PASCAL AboutDlgProc( HWND hDlg, WORD wMsg,
  72.  *                                WORD wParam, LONG lParam )
  73.  *
  74.  *  Description: 
  75.  *     Puts up the ego boosting about box. :)
  76.  *
  77.  *  Comments:
  78.  *       5/10/91  baw  Needed an ego boost... So I wrote this
  79.  *                     about box.
  80.  *
  81.  ************************************************************************/
  82.  
  83. BOOL FAR PASCAL AboutDlgProc( HWND hDlg, WORD wMsg, WORD wParam, LONG lParam )
  84. {
  85.    switch (wMsg)
  86.    {
  87.       case WM_INITDIALOG:
  88.       {
  89.          char  szBuffer[ 25 ] ;
  90.  
  91.          wsprintf( szBuffer, "Version: %s", (LPSTR) szVersion ) ;
  92.          SetDlgItemText( hDlg, IDD_VERSION, (LPSTR) szBuffer ) ;
  93.       }
  94.       return ( TRUE ) ;
  95.  
  96.       case WM_COMMAND:
  97.          if (wParam == IDD_OK)
  98.          {
  99.             EndDialog( hDlg, TRUE ) ;
  100.             return ( TRUE ) ;
  101.          }
  102.          break;
  103.    }
  104.    return ( FALSE ) ;
  105.  
  106. } /* end of AboutDlgProc() */
  107.  
  108. /************************************************************************
  109.  *  BOOL SettingsDlgInit( HWND hDlg, LOCALHANDLE hTermInfo )
  110.  *
  111.  *  Description: 
  112.  *     Puts current settings into dialog box (via CheckRadioButton() etc.)
  113.  *
  114.  *  Comments:
  115.  *      5/11/91  baw  Wrote it.
  116.  *
  117.  ************************************************************************/
  118.  
  119. BOOL SettingsDlgInit( HWND hDlg, LOCALHANDLE hTermInfo )
  120. {
  121.    int         i ;
  122.    NPTERMINFO  npTermInfo ;
  123.  
  124.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  125.       return ( FALSE ) ;
  126.  
  127.    CheckRadioButton( hDlg, IDD_COM1, IDD_COM4,
  128.                      npTermInfo -> bPort + IDD_COM1 - 1 ) ;
  129.  
  130.    // disable COM port options if connected
  131.  
  132.    for (i = IDD_COM1; i <= IDD_COM4; i++)
  133.       EnableWindow( GetDlgItem( hDlg, i ), !(npTermInfo -> fConnected) ) ;
  134.  
  135.    for (i = 0; i < MAXBAUDRATES; i++)
  136.       if (npTermInfo -> wBaudRate == awBaudRates[i])
  137.          break;
  138.    CheckRadioButton( hDlg, IDD_1200, IDD_9600, IDD_1200 + i ) ;
  139.  
  140.    CheckRadioButton( hDlg, IDD_DATABITS5, IDD_DATABITS8,
  141.                      IDD_DATABITS5 + npTermInfo -> bByteSize - 5 ) ;
  142.    CheckRadioButton( hDlg, IDD_NONE, IDD_SPACE,
  143.                      IDD_NONE + npTermInfo -> bParity - NOPARITY ) ;
  144.    CheckRadioButton( hDlg, IDD_STOPBITS1, IDD_STOPBITS2,
  145.                      IDD_STOPBITS1 + npTermInfo -> bStopBits - ONESTOPBIT ) ;
  146.    CheckDlgButton( hDlg, IDD_HARDWARE,
  147.                    (npTermInfo -> bFlowCtrl & FC_HARDWARE) > 0 ) ;
  148.    CheckDlgButton( hDlg, IDD_SOFTWARE,
  149.                    (npTermInfo -> bFlowCtrl & FC_SOFTWARE) > 0 ) ;
  150.    CheckDlgButton( hDlg, IDD_AUTOWRAP, npTermInfo -> fAutoWrap ) ;
  151.    CheckDlgButton( hDlg, IDD_NEWLINE, npTermInfo -> fNewLine ) ;
  152.    CheckDlgButton( hDlg, IDD_LOCALECHO, npTermInfo -> fLocalEcho ) ;
  153.  
  154.    LocalUnlock( hTermInfo ) ;
  155.    return ( TRUE ) ;
  156.  
  157. } /* end of SettingsDlgInit() */
  158.  
  159. /************************************************************************
  160.  *  BOOL SettingsDlgTerm( HWND hDlg, LOCALHANDLE hTermInfo )
  161.  *
  162.  *  Description: 
  163.  *     Puts dialog contents into current settings.
  164.  *
  165.  *  Comments:
  166.  *      5/11/91  baw  Wrote it.
  167.  *
  168.  ************************************************************************/
  169.  
  170. BOOL SettingsDlgTerm( HWND hDlg, LOCALHANDLE hTermInfo )
  171. {
  172.    NPTERMINFO  npTermInfo ;
  173.  
  174.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  175.       return ( FALSE ) ;
  176.  
  177.    if (!npTermInfo -> fConnected)
  178.       npTermInfo -> bPort =
  179.          (BYTE)(GetRadioButton( hDlg, IDD_COM1, IDD_COM4 ) - IDD_COM1 + 1) ;
  180.    npTermInfo -> wBaudRate =
  181.       awBaudRates[GetRadioButton( hDlg, IDD_1200, IDD_9600 ) - IDD_1200] ;
  182.    npTermInfo -> bByteSize =
  183.       (BYTE)(GetRadioButton( hDlg, IDD_DATABITS5, IDD_DATABITS8 ) - IDD_DATABITS5 + 5 ) ;
  184.    npTermInfo -> bParity =
  185.       (BYTE)(GetRadioButton( hDlg, IDD_NONE, IDD_SPACE ) - IDD_NONE + NOPARITY) ;
  186.    npTermInfo -> bStopBits =
  187.       (BYTE)(GetRadioButton( hDlg, IDD_STOPBITS1, IDD_STOPBITS2 ) - IDD_STOPBITS1 + ONESTOPBIT) ;
  188.  
  189.    if (IsDlgButtonChecked( hDlg, IDD_HARDWARE))
  190.       npTermInfo -> bFlowCtrl |= FC_HARDWARE ;
  191.    else
  192.       npTermInfo -> bFlowCtrl &= ~FC_HARDWARE ;
  193.    if (IsDlgButtonChecked( hDlg, IDD_SOFTWARE))
  194.       npTermInfo -> bFlowCtrl |= FC_SOFTWARE ;
  195.    else
  196.       npTermInfo -> bFlowCtrl &= ~FC_SOFTWARE ;
  197.    npTermInfo -> fAutoWrap = IsDlgButtonChecked( hDlg, IDD_AUTOWRAP ) ;
  198.    npTermInfo -> fNewLine = IsDlgButtonChecked( hDlg, IDD_NEWLINE ) ;
  199.    npTermInfo -> fLocalEcho = IsDlgButtonChecked( hDlg, IDD_LOCALECHO ) ;
  200.  
  201.    LocalUnlock( hTermInfo ) ;
  202.    return ( TRUE ) ;
  203.  
  204. } /* end of SettingsDlgTerm() */
  205.  
  206. /************************************************************************
  207.  *  BOOL FAR PASCAL SettingsDlgProc( HWND hDlg, WORD wMsg,
  208.  *                                   WORD wParam, LONG lParam )
  209.  *
  210.  *  Description: 
  211.  *     This handles all of the settings for Terminal.
  212.  *
  213.  *  Comments:
  214.  *      5/10/91  baw  Wrote it.
  215.  *
  216.  ************************************************************************/
  217.  
  218. BOOL FAR PASCAL SettingsDlgProc( HWND hDlg, WORD wMsg,
  219.                                  WORD wParam, LONG lParam )
  220. {
  221.    static LOCALHANDLE  hTermInfo ;
  222.  
  223.    switch (wMsg)
  224.    {
  225.       case WM_INITDIALOG:
  226.          hTermInfo = LOWORD( lParam ) ;
  227.          return ( SettingsDlgInit( hDlg, hTermInfo ) ) ;
  228.  
  229.       case WM_COMMAND:
  230.          switch (wParam)
  231.          {
  232.             case IDD_COM1:
  233.             case IDD_COM2:
  234.             case IDD_COM3:
  235.             case IDD_COM4:
  236.                CheckRadioButton( hDlg, IDD_COM1, IDD_COM4, wParam ) ;
  237.                return ( TRUE ) ;
  238.  
  239.             case IDD_1200:
  240.             case IDD_2400:
  241.             case IDD_4800:
  242.             case IDD_9600:
  243.                CheckRadioButton( hDlg, IDD_1200, IDD_9600, wParam ) ;
  244.                return ( TRUE ) ;
  245.  
  246.             case IDD_DATABITS5:
  247.             case IDD_DATABITS6:
  248.             case IDD_DATABITS7:
  249.             case IDD_DATABITS8:
  250.                CheckRadioButton( hDlg, IDD_DATABITS5, IDD_DATABITS8, wParam ) ;
  251.                return ( TRUE ) ;
  252.  
  253.             case IDD_NONE:
  254.             case IDD_EVEN:
  255.             case IDD_ODD:
  256.             case IDD_MARK:
  257.             case IDD_SPACE:
  258.                CheckRadioButton( hDlg, IDD_NONE, IDD_SPACE, wParam ) ;
  259.                return ( TRUE ) ;
  260.  
  261.             case IDD_STOPBITS1:
  262.             case IDD_STOPBITS15:
  263.             case IDD_STOPBITS2:
  264.                CheckRadioButton( hDlg, IDD_STOPBITS1, IDD_STOPBITS2, wParam ) ;
  265.                return ( TRUE ) ;
  266.  
  267.             case IDD_OK:
  268.                // Copy stuff into structure
  269.                SettingsDlgTerm( hDlg, hTermInfo ) ;
  270.                EndDialog( hDlg, TRUE ) ;
  271.                return ( TRUE ) ;
  272.  
  273.             case IDD_CANCEL:
  274.                // Just end
  275.                EndDialog( hDlg, TRUE ) ;
  276.                return ( TRUE ) ;
  277.          }
  278.          break;
  279.    }
  280.    return ( FALSE ) ;
  281.  
  282. } /* end of SettingsDlgProc() */
  283.  
  284. /************************************************************************
  285.  * End of File: dialog.c
  286.  ************************************************************************/
  287.  
  288.